import { defineStore } from 'pinia';
import { ref } from "vue";

export const useStore = defineStore('policyUser', () => {
  //
  const list = ref([] as any)
  //获取单条记录
  const getPolicy = (id: number) => {
    return list.value?.find((x: any) => x.id === id);
  }
  //设置单条记录
  const setPolicy = (record: any) => {
    removePolicy(record.id);
    list.value.push(record);
  }
  //清除单条记录
  const removePolicy = (id: number) => {
    const idx = list.value.findIndex((x: any) => x.id === id);
    idx > -1 && list.value.splice(idx, 1);
  }
  //全部清除
  const clearPolicy = () => {
    list.value = [];
  }
  return {
    list,
    getPolicy,
    setPolicy,
    removePolicy,
    clearPolicy,
  }
})